<?php
namespace Library;

use Hoa\Registry\Registry;
use Library\Log;
use Memcached;


/**
* Mc
*/
class Mc {
	//本类单实例变量
	static private $inst = NULL;
	//Memcache类实例
	private $mc = NULL;


	/**
	 * 构造函数
	 * 依赖外部传入参数，用于实例化monolog日志类
	 */
	private function __construct() {
		$conf = Registry::get('conf');
		$this->mc = new Memcached;
		$this->mc->addServers($conf['mc']['server_list']);
	}


	/**
	 * 获取本类实例
	 */
	static private function getInst() {
		if (null === self::$inst) {
			self::$inst = new self();
		}
		return self::$inst;
	}


	/**
	 * 魔术方法，统一处理静态函数的调用
	 * @param string $method
	 * @param array $args
	 */
	public static function __callStatic($method, $args) {
		return self::getInst()->process($method, $args);
	}


	/**
	 * 调用Memcache，操作Mc Server
	 * @param string $method
	 * @param array $args
	 */
	private function process($method, $args) {
		$result = false;
		$result = call_user_func_array([$this->mc, $method], $args);
		return $result;
	}


}